import java.io.File;
import java.io.FileFilter;

//*****************************************************
//void excution(String Path, ArrayList<Category> CategoryList)
//		Change all the directory of file with CategoryList in Path
//void undo(String Path, ArrayList<Category> CategoryList)
//		Undo after excution
//***********************************************************

class FileControler{
	
	public static File[] extractFile(String Path){
		File[] SortFolder = new File(Path).listFiles(new FileFilter(){
			public boolean accept(File Pathname){
				return Pathname.isFile();
			}
		});
		
		return SortFolder;
	}
	
	public static void excution(String Path, CategoryList ongoingCate){
		try{
			for(int i=1;i<ongoingCate.size();i++){
				File MkDir = new File(Path+"/"+ongoingCate.get(i).getName());
				MkDir.mkdir();
				for(int j=0;j<ongoingCate.get(i).getSize();j++){
					File mvFile = new File(MkDir.getAbsolutePath()+"/"+ongoingCate.get(i).getFileName(j));
					ongoingCate.get(i).getFile(j).renameTo(mvFile);
				}
			}
		}
		catch(Exception e){
			System.out.println();
		}
	}

	public static void undo(String Path, CategoryList ongoingCate){
		for(int i=1;i<ongoingCate.size();i++){
			File rmDir = new File(Path+"/"+ongoingCate.get(i).getName());
			for(int j=0;j<ongoingCate.get(i).getSize();j++){
				File mvFile = new File(rmDir.getAbsolutePath()+"/"+ongoingCate.get(i).getFileName(j));
				mvFile.renameTo(ongoingCate.get(i).getFile(j));
			}
			rmDir.delete();
		}
	}
	
}


